﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Shapes;

namespace MapEditor.Model
{
    public class GameObject
    {
        public Rect Rect { get; set; }
        public int Id { get; set; }
        public int Type { get; set; }
        public int LimitLeft { get; set; }
        public int LimitRight { get; set; }

        public GameObject(int Type)
        {
            this.Type = Type;
            this.Rect = new Rect();
        }

        /// <summary>
        /// Create game object from rectangle
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="Type"></param>
        /// <returns></returns>
        public static GameObject createGameObject(int Id, Rectangle rect, int LimitLeft, int limitRight, int Type)
        {
            GameObject result = new GameObject(Type);
            result.Id = Id;
            result.Rect.Width = rect.Width;
            result.Rect.Height = rect.Height;
            result.Rect.X = Canvas.GetLeft(rect) + rect.Width / 2;
            result.Rect.Y = Canvas.GetTop(rect) + rect.Height / 2;
            result.LimitLeft = LimitLeft;
            result.LimitRight = limitRight;
                
            return result;
        }

        /// <summary>
        /// Create game object from rectangle
        /// </summary>
        /// <param name="rect"></param>
        /// <returns></returns>
        public static GameObject createGameObject(int ID, Rectangle rect, int LimitLeft, int limitRight)
        {
            GameObject result = createGameObject(ID, rect, LimitLeft, limitRight, 0);

            return result;
        }

        /// <summary>
        /// Get game objet data to save
        /// </summary>
        /// <param name="result"></param>
        public void serialize(ref string result)
        {
            result += this.Id.ToString() + " " + this.Type.ToString() + " " + this.Rect.ToString() + " " + this.LimitLeft.ToString() + " " + this.LimitRight + " ";
        }
    }
}
